package com.atguigu.gmall.cart.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.cart.service.CartInfoAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author ：MJS
 * @date ：Created in 2021/5/24  22:14
 * @description：TODO
 */
@Service
public class CartInfoAsyncServiceImpl implements CartInfoAsyncService{
    @Autowired
    private CartInfoMapper cartInfoMapper;
   //更新DB购物车
    @Override
    @Async   //开启一个新线程  来执行方法   异步的
    public void updateAsyncById(CartInfo cartInfo) {
        System.out.println("updateAsyncById:"+ Thread.currentThread().getName());
//        cartInfoMapper.update(cartInfo,new QueryWrapper<CartInfo>().eq("user_id",cartInfo.getUserId()).eq("sku_id",cartInfo.getSkuId()));
        cartInfoMapper.updateById(cartInfo);
    }
    //添加db购物车
    @Override
    @Async
    public void insertAsync(CartInfo cartInfo) {
        System.out.println("insertAsync:"+ Thread.currentThread().getName());
        cartInfoMapper.insert(cartInfo);
    }
}
